// Copyright (C) 2010 Johan Rende.

//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.

//	Official SVN repository and contact information can be found at
//	https://code.google.com/p/lt-engine/

package jwjgl;

import java.awt.Rectangle;
import org.lwjgl.opengl.GL11;

public class Player {
//	public int x,y = 0;
	public float angle = 0;
	public float size = 64;
	public Rectangle plrect;
	float y = 536;
	float a = -9.82f;
	float v = 0;
	float f = 0;
	float m = 10;
	float t;
	int vPix;
	
	
	public Player(int x0,int y0,int w0, int h0){
		
		plrect = new Rectangle();
		plrect.x = x0;
		plrect.y = y0;
		plrect.width = w0;
		plrect.height = h0;

		
	}
	public void calculateYPos(){
//		f=m*a;
		v=v+a*t;
		y=y+v*t;
		vPix =(plrect.y-(int) y);
		
		plrect.y = (int) y;
	}
	public void draw(){
		
		GL11.glPushMatrix();
		GL11.glTranslatef(plrect.x, plrect.y, 0);
		
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, Textures.texcharint);
		DrawObj.drawSquare(plrect.width,plrect.height);
		GL11.glPopMatrix();
		
	}
	public void printstats() {
		System.out.println("x = " + plrect.x);
		System.out.println("y = " + plrect.y);
		System.out.println("storlek = " + size);
	}
	public void checkCollision(){
		//kolla ned�t
		int platIndex = Collision.collisionDetect(plrect,2,vPix);
		
		if(platIndex!=-1 && plrect.y > Main.lvl[Main.currentLevelX][Main.currentLevelY].plat[platIndex].rect.y-60){
			v=-v/2;
			a=0;
			plrect.y = Main.lvl[Main.currentLevelX][Main.currentLevelY].plat[platIndex].rect.y+60;
			vPix = 0;
			System.out.println("platindex = " + platIndex);
		}
//		platIndex = Collision.collisionDetect(plrect,8,vPix);
		if(platIndex!=-1 && plrect.y < Main.lvl[Main.currentLevelX][Main.currentLevelY].plat[platIndex].rect.y){
			v=-v;
			a=0;
			vPix = 0;
			plrect.y = Main.lvl[Main.currentLevelX][Main.currentLevelY].plat[platIndex].rect.y-128;
		}
		else{
			a=-9.82f;
		}
	}
	public void moveX(int dir) {
		if(dir > 0){
			//G� h�ger
			if(Collision.collisionDetect(plrect,6,3)==-1){
			plrect.x -= 3;
			
			}
		}
		if(dir < 0){
			//g� v�nster
			if(Collision.collisionDetect(plrect,4,3)==-1){
			plrect.x += 3;
			}
		}
		
	}

}
